package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Presenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay00108 extends BasterFragment implements BaseDay00108Contion.vier, OnRefreshLoadMoreListener {


    public BaseDay00108Adpter adpter;
    public BaseDay00108Presenter presenter;
    private RecyclerView day00108RecyclerView;
    public static SmartRefreshLayout day00108SmartRefreshLayout;
    public boolean ising = true;
    public  int contger=70;
    public  int kaomei =0;



    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00108;
    }

    @Override
    public void initView() {
        day00108RecyclerView = (RecyclerView) findViewById(R.id.day00108_RecyclerView);
        day00108RecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        day00108SmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.day00108_SmartRefreshLayout);
        day00108SmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        presenter = new BaseDay00108Presenter(this,new BaseDay00108Model());
        presenter.dogetin("/video/findVideos?currentPage="+contger+"&pageSize=10");
    }

    @Override
    public void initDate() {

    }

    @Override
    public void getvier(List<BaseDay00108Bean.DataBean> dataBeans) {
        for (BaseDay00108Bean.DataBean dataBean : dataBeans) {
            dataBean.setHaoduoyu(++kaomei);
            if (kaomei==4){
                kaomei=0;
            }
        }
        day00108SmartRefreshLayout.finishLoadMore();
        day00108SmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new BaseDay00108Adpter(dataBeans);
            day00108RecyclerView.setAdapter(adpter);
        }else {
            if (ising){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }

    }


    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        ising=false;
        contger++;
        presenter.dogetin("/video/findVideos?currentPage="+contger+"&pageSize=10");
        Log.i("BlankFragmentDay001","---08加载:"+contger);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (ising){
            contger=70;
        }
        presenter.dogetin("/video/findVideos?currentPage="+contger+"&pageSize=10");

        Log.i("BlankFragmentDay001","---08刷新:"+contger);
    }
}
